package cn.iocoder.yudao.module.erp.dal.mysql.secaccount;

import java.util.*;

import cn.hutool.core.date.DateTime;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.erp.dal.dataobject.secaccount.SecAccountDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.erp.controller.admin.secaccount.vo.*;

/**
 * ERP 二级库台账 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface SecAccountMapper extends BaseMapperX<SecAccountDO> {

    default PageResult<SecAccountDO> selectPage(SecAccountPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SecAccountDO>()
                .eqIfPresent(SecAccountDO::getAffairs, reqVO.getAffairs())
                .eqIfPresent(SecAccountDO::getAffairsId, reqVO.getAffairsId())
                .eqIfPresent(SecAccountDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(SecAccountDO::getFromDeptId, reqVO.getFromDeptId())
                .eqIfPresent(SecAccountDO::getToDeptId, reqVO.getToDeptId())
                .eqIfPresent(SecAccountDO::getProductId, reqVO.getProductId())
                .likeIfPresent(SecAccountDO::getProductName, reqVO.getProductName())
                .eqIfPresent(SecAccountDO::getProductUnit, reqVO.getProductUnit())
                .eqIfPresent(SecAccountDO::getProductStandards, reqVO.getProductStandards())
                .eqIfPresent(SecAccountDO::getProductPrice, reqVO.getProductPrice())
                .eqIfPresent(SecAccountDO::getProductPurchasePrice, reqVO.getProductPurchasePrice())
                .eqIfPresent(SecAccountDO::getProductBatch, reqVO.getProductBatch())
                .betweenIfPresent(SecAccountDO::getProductValidityDate, reqVO.getProductValidityDate())
                .eqIfPresent(SecAccountDO::getCount, reqVO.getCount())
                .eqIfPresent(SecAccountDO::getRemark, reqVO.getRemark())
                .eqIfPresent(SecAccountDO::getStatus, reqVO.getStatus())
                .eqIfPresent(SecAccountDO::getProcessInstanceId, reqVO.getProcessInstanceId())
                .eqIfPresent(SecAccountDO::getCreator, reqVO.getCreator())
                .betweenIfPresent(SecAccountDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SecAccountDO::getId));
    }

    default List<SecAccountDO> getStock(String deptId, String productId, String affairs, DateTime outInTimeS, DateTime outInTimeE){
        return selectList(new LambdaQueryWrapperX<SecAccountDO>()
                .eqIfPresent(SecAccountDO::getDeptId, deptId)
                .eqIfPresent(SecAccountDO::getProductId, productId)
                .eqIfPresent(SecAccountDO::getAffairs, affairs)
                .betweenIfPresent(SecAccountDO::getCreateTime, outInTimeS, outInTimeE));
    }
}